<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="UIViewAnimation先了解一哈子CGAffineTransform">
<meta property="og:type" content="article">
<meta property="og:title" content="UIViewAnimation">
<meta property="og:url" content="http://yoursite.com/2018/07/14/UIViewAnimation/index.html">
<meta property="og:site_name" content="Erhqe">
<meta property="og:description" content="UIViewAnimation先了解一哈子CGAffineTransform">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://ws4.sinaimg.cn/large/006tNc79ly1ft9cdlt0xwg306g07kwei.gif">
<meta property="og:image" content="https://ws2.sinaimg.cn/large/006tNc79ly1ft9bnp5lfxg305k09laa6.gif">
<meta property="og:image" content="https://ws4.sinaimg.cn/large/006tNc79ly1ft9bdcw5iqg306a08k0sr.gif">
<meta property="og:image" content="https://ws4.sinaimg.cn/large/006tNc79ly1ft9c7mcwv5g306b07jwey.gif">
<meta property="og:image" content="https://ws2.sinaimg.cn/large/006tNc79ly1ft9eowfavdg305b074t8q.gif">
<meta property="og:updated_time" content="2019-07-19T05:40:06.082Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="UIViewAnimation">
<meta name="twitter:description" content="UIViewAnimation先了解一哈子CGAffineTransform">
<meta name="twitter:image" content="https://ws4.sinaimg.cn/large/006tNc79ly1ft9cdlt0xwg306g07kwei.gif">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/07/14/UIViewAnimation/"/>





  <title>UIViewAnimation | Erhqe</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Erhqe</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/07/14/UIViewAnimation/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Erhqe">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/10.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Erhqe">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">UIViewAnimation</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-07-14T10:35:26+08:00">
                2018-07-14
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Animation/" itemprop="url" rel="index">
                    <span itemprop="name">Animation</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/07/14/UIViewAnimation/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2018/07/14/UIViewAnimation/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="UIViewAnimation"><a href="#UIViewAnimation" class="headerlink" title="UIViewAnimation"></a>UIViewAnimation</h4><p><strong>先了解一哈子CGAffineTransform</strong><a id="more"></a></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">@property(nonatomic) CGAffineTransform transform;  // view 的属性</span><br><span class="line">@property CATransform3D transform; // layer 的属性</span><br></pre></td></tr></table></figure>
<p><strong>CGAffineTransform transform 一般用于 伸缩,平移,旋转</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">self</span>.lable.transform = <span class="type">CGAffineTransform</span>(scaleX: <span class="number">0.5</span>, y: <span class="number">0.5</span>)</span><br><span class="line"><span class="keyword">self</span>.lable.transform = <span class="type">CGAffineTransform</span>(translationX: <span class="number">0</span>, y: <span class="number">200</span>)</span><br><span class="line"><span class="keyword">self</span>.lable.transform = <span class="type">CGAffineTransform</span>(rotationAngle: .pi )</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">UIView</span>.animate(withDuration: <span class="number">0.2</span>, animations: &#123;</span><br><span class="line">          <span class="comment">//self.lable.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)</span></span><br><span class="line">          <span class="comment">//self.lable.transform = CGAffineTransform(translationX: 0, y: 200)</span></span><br><span class="line">          <span class="keyword">self</span>.lable.transform = <span class="type">CGAffineTransform</span>(rotationAngle: .pi )</span><br><span class="line">        &#125;, completion: <span class="literal">nil</span>)</span><br></pre></td></tr></table></figure>
<p><strong>CATransform3D transform通常用于3D模式下的变换</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">touchesBegan</span><span class="params">(<span class="number">_</span> touches: Set&lt;UITouch&gt;, with event: UIEvent?)</span></span> &#123;</span><br><span class="line">        lable.layer.transform = <span class="type">CATransform3DIdentity</span></span><br><span class="line">        <span class="type">UIView</span>.animate(withDuration: <span class="number">0.2</span>, animations: &#123;</span><br><span class="line">            <span class="keyword">self</span>.lable.layer.transform = <span class="type">CATransform3DScale</span>(<span class="keyword">self</span>.lable.layer.transform, <span class="number">2</span>, <span class="number">2</span>, <span class="number">1</span>)</span><br><span class="line">        &#125;, completion: <span class="literal">nil</span>)</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h5 id="CGAffineTransform"><a href="#CGAffineTransform" class="headerlink" title="CGAffineTransform"></a>CGAffineTransform</h5><figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//带Make的会基于上一次的transform作为标准</span></span><br><span class="line"><span class="comment">//不带Make的会自动identity</span></span><br><span class="line"><span class="comment">//	重置</span></span><br><span class="line"><span class="type">CGAffineTransformIdentity</span> → <span class="type">Swift</span> <span class="type">CGAffineTransform</span>.identity</span><br><span class="line"></span><br><span class="line"><span class="comment">//位移仿射  ---- 理解为平移 (CGFloat tx,CGFloat ty) </span></span><br><span class="line"><span class="type">CGAffineTransformMakeTranslation</span> → <span class="type">Swift</span> <span class="keyword">self</span>.lable.transform.translatedBy</span><br><span class="line"><span class="type">CGAffineTransformTranslate</span> </span><br><span class="line"><span class="comment">//旋转仿射 ---- 理解为旋转 (CGFloat angle)</span></span><br><span class="line"><span class="type">CGAffineTransformMakeRotation</span> → <span class="type">Swift</span> <span class="keyword">self</span>.lable.transform.rotated(by: &lt;#<span class="type">T</span>##<span class="type">CGFloat</span>#&gt;)</span><br><span class="line"><span class="type">CGAffineTransformRotate</span> </span><br><span class="line"><span class="comment">//缩放仿射  --- 理解缩放大小 (CGFloat sx, CGFloat sy)</span></span><br><span class="line"><span class="type">CGAffineTransformMakeScale</span> → <span class="type">Swift</span> <span class="keyword">self</span>.lable.transform.scaledBy</span><br><span class="line"><span class="type">CGAffineTransformScale</span></span><br></pre></td></tr></table></figure>
<p><strong>CATransform3D</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">CATransform3DIdentity</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">//位移3D仿射  ==&gt; (CGFloat tx, CGFloat ty, CGFloat tz)</span></span><br><span class="line"><span class="type">CATransform3DMakeTranslation</span></span><br><span class="line"><span class="type">CATransform3DTranslation</span>        </span><br><span class="line"><span class="comment">//旋转3D仿射 ==&gt; (CGFloat angle, CGFloat x, CGFloat y, CGFloat z)</span></span><br><span class="line"><span class="type">CATransform3DMakeRotation</span></span><br><span class="line"><span class="type">CATransform3DRotation</span>  </span><br><span class="line"><span class="comment">//缩放3D仿射 ==&gt;  (CGFloat angle, CGFloat x, CGFloat y, CGFloat z)</span></span><br><span class="line"><span class="type">CATransform3DMakeScale</span></span><br><span class="line"><span class="type">CATransform3DScale</span></span><br><span class="line"><span class="comment">//叠加3D仿射效果</span></span><br><span class="line"><span class="type">CATransform3DConcat</span>    </span><br><span class="line"><span class="comment">//仿射基础3D方法，可以直接做效果叠加</span></span><br><span class="line"><span class="type">CGAffineTransformMake</span> (sx,shx,shy,sy,tx,ty)</span><br><span class="line"><span class="comment">//检查是否有做过仿射3D效果  == ((CATransform3D t))</span></span><br><span class="line"><span class="type">CATransform3DIsIdentity</span>(transform)</span><br><span class="line"><span class="comment">//检查2个3D仿射效果是否相同</span></span><br><span class="line"><span class="type">CATransform3DEqualToTransform</span>(transform1,transform2)</span><br><span class="line"><span class="comment">//3D仿射效果反转（反效果，比如原来扩大，就变成缩小）</span></span><br><span class="line"><span class="type">CATransform3DInvert</span>(transform)</span><br></pre></td></tr></table></figure>
<h4 id="UIViewAnimation-1"><a href="#UIViewAnimation-1" class="headerlink" title="UIViewAnimation"></a>UIViewAnimation</h4><p><strong>基本动画</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">animate(withDuration duration: <span class="type">TimeInterval</span>, animations: @escaping () -&gt; <span class="type">Swift</span>.<span class="type">Void</span>, completion: ((<span class="type">Bool</span>) -&gt; <span class="type">Swift</span>.<span class="type">Void</span>)? = <span class="literal">nil</span></span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">// 修改这些属性可有动画</span><br><span class="line">@property frame</span><br><span class="line">@property bounds</span><br><span class="line">@property center</span><br><span class="line">@property transform</span><br><span class="line">@property alpha</span><br><span class="line">@property backgroundColor</span><br><span class="line">@property contentStretch</span><br></pre></td></tr></table></figure>
<p><strong>延迟动画</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">animate(withDuration duration: <span class="type">TimeInterval</span>, delay: <span class="type">TimeInterval</span>, options: <span class="type">UIViewAnimationOptions</span> = [], animations: @escaping () -&gt; <span class="type">Swift</span>.<span class="type">Void</span>, completion: ((<span class="type">Bool</span>) -&gt; <span class="type">Swift</span>.<span class="type">Void</span>)? = <span class="literal">nil</span>)</span><br></pre></td></tr></table></figure>
<p><strong>弹性动画</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//Damping  阻尼 范围0.0~1.0</span></span><br><span class="line"><span class="comment">//velocity	起始速度,速度越大,弹的幅度也就越大</span></span><br><span class="line">animate(withDuration duration: <span class="type">TimeInterval</span>, delay: <span class="type">TimeInterval</span>, usingSpringWithDamping dampingRatio: <span class="type">CGFloat</span>, initialSpringVelocity velocity: <span class="type">CGFloat</span>, options: <span class="type">UIViewAnimationOptions</span> = [], animations: @escaping () -&gt; <span class="type">Swift</span>.<span class="type">Void</span>, completion: ((<span class="type">Bool</span>) -&gt; <span class="type">Swift</span>.<span class="type">Void</span>)? = <span class="literal">nil</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">touchesBegan</span><span class="params">(<span class="number">_</span> touches: Set&lt;UITouch&gt;, with event: UIEvent?)</span></span> &#123;</span><br><span class="line">   <span class="type">UIView</span>.animate(withDuration: <span class="number">1</span>, delay: <span class="number">0</span>, usingSpringWithDamping: <span class="number">0.1</span>, initialSpringVelocity: <span class="number">1</span>, options: [], animations: &#123;</span><br><span class="line">        <span class="keyword">self</span>.lable.transform = <span class="type">CGAffineTransform</span> (scaleX: <span class="number">0.5</span>, y: <span class="number">0.5</span>)</span><br><span class="line">     &#125;) &#123; (finished) <span class="keyword">in</span></span><br><span class="line">            </span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://ws4.sinaimg.cn/large/006tNc79ly1ft9cdlt0xwg306g07kwei.gif" alt=""></p>
<p><strong>转场动画</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">fileprivate</span> <span class="built_in">lazy</span> <span class="keyword">var</span> lable : <span class="type">UILabel</span> = <span class="type">UILabel</span>(frame: <span class="type">CGRect</span> (x: <span class="number">0</span>, y: <span class="number">100</span>, width: <span class="number">100</span>, height: <span class="number">100</span>))</span><br><span class="line"><span class="keyword">fileprivate</span> <span class="built_in">lazy</span> <span class="keyword">var</span> subView = <span class="type">UIView</span>(frame: <span class="type">CGRect</span> (x: <span class="number">0</span>, y: <span class="number">0</span>, width: <span class="number">100</span>, height: <span class="number">100</span>))</span><br><span class="line"><span class="keyword">fileprivate</span> <span class="built_in">lazy</span> <span class="keyword">var</span> view_1 = <span class="type">UIView</span>(frame: <span class="type">CGRect</span> (x: <span class="number">0</span>, y: <span class="number">0</span>, width: <span class="number">100</span>, height: <span class="number">100</span>))</span><br><span class="line">    <span class="meta">@IBOutlet</span> <span class="keyword">weak</span> <span class="keyword">var</span> we: <span class="type">WE</span>!</span><br><span class="line"></span><br><span class="line">    <span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">viewDidLoad</span><span class="params">()</span></span> &#123;</span><br><span class="line">        <span class="keyword">super</span>.viewDidLoad()</span><br><span class="line">        lable.center = view.center</span><br><span class="line">        </span><br><span class="line">        view.backgroundColor = .white</span><br><span class="line">        lable.backgroundColor = .orange</span><br><span class="line">        subView.backgroundColor = .green</span><br><span class="line">        view_1.backgroundColor = .red</span><br><span class="line">        </span><br><span class="line">        view.addSubview(lable)</span><br><span class="line"><span class="comment">//        lable.addSubview(subView)</span></span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">touchesBegan</span><span class="params">(<span class="number">_</span> touches: Set&lt;UITouch&gt;, with event: UIEvent?)</span></span> &#123;</span><br><span class="line">      <span class="comment">// options: [.transitionFlipFromLeft,.repeat]	//重复执行</span></span><br><span class="line">  	<span class="type">UIView</span>.transition(with: lable, duration: <span class="number">1</span>, options: .transitionFlipFromLeft, animations: &#123;</span><br><span class="line">            <span class="keyword">self</span>.lable.addSubview(<span class="keyword">self</span>.subView)</span><br><span class="line">        &#125;) &#123; (finished) <span class="keyword">in</span></span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://ws2.sinaimg.cn/large/006tNc79ly1ft9bnp5lfxg305k09laa6.gif" alt=""></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">fileprivate</span> <span class="built_in">lazy</span> <span class="keyword">var</span> lable : <span class="type">UILabel</span> = <span class="type">UILabel</span>(frame: <span class="type">CGRect</span> (x: <span class="number">0</span>, y: <span class="number">100</span>, width: <span class="number">100</span>, height: <span class="number">100</span>))</span><br><span class="line"><span class="keyword">fileprivate</span> <span class="built_in">lazy</span> <span class="keyword">var</span> subView = <span class="type">UIView</span>(frame: <span class="type">CGRect</span> (x: <span class="number">0</span>, y: <span class="number">0</span>, width: <span class="number">100</span>, height: <span class="number">100</span>))</span><br><span class="line"><span class="keyword">fileprivate</span> <span class="built_in">lazy</span> <span class="keyword">var</span> view_1 = <span class="type">UIView</span>(frame: <span class="type">CGRect</span> (x: <span class="number">0</span>, y: <span class="number">0</span>, width: <span class="number">100</span>, height: <span class="number">100</span>))</span><br><span class="line">    <span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">viewDidLoad</span><span class="params">()</span></span> &#123;</span><br><span class="line">        <span class="keyword">super</span>.viewDidLoad()</span><br><span class="line">        lable.center = view.center</span><br><span class="line">        </span><br><span class="line">        view.backgroundColor = .white</span><br><span class="line">        lable.backgroundColor = .orange</span><br><span class="line">        subView.backgroundColor = .green</span><br><span class="line">        view_1.backgroundColor = .red</span><br><span class="line">        </span><br><span class="line">        view.addSubview(lable)</span><br><span class="line">        lable.addSubview(subView)</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">touchesBegan</span><span class="params">(<span class="number">_</span> touches: Set&lt;UITouch&gt;, with event: UIEvent?)</span></span> &#123;</span><br><span class="line">        <span class="comment">//  夫视图的动画,如果subView的夫视图是控制器的View那么控制器的View会发生动画</span></span><br><span class="line">        <span class="type">UIView</span>.transition(from: subView, to: view_1, duration: <span class="number">0.5</span>, options: .transitionFlipFromLeft) &#123; (finished) <span class="keyword">in</span></span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://ws4.sinaimg.cn/large/006tNc79ly1ft9bdcw5iqg306a08k0sr.gif" alt=""></p>
<p><strong>Options</strong></p>
<p><strong>动画效果相关</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">UIViewAnimationOptionLayoutSubviews            //提交动画的时候布局子控件，表示子控件将和父控件一同动画。</span><br><span class="line">UIViewAnimationOptionAllowUserInteraction      //动画时允许用户交流，比如触摸</span><br><span class="line">UIViewAnimationOptionBeginFromCurrentState     //从当前状态开始动画</span><br><span class="line">UIViewAnimationOptionRepeat                    //动画无限重复</span><br><span class="line">UIViewAnimationOptionAutoreverse               //执行动画回路,前提是设置动画无限重复</span><br><span class="line">UIViewAnimationOptionOverrideInheritedDuration //忽略外层动画嵌套的执行时间</span><br><span class="line">UIViewAnimationOptionOverrideInheritedCurve    //忽略外层动画嵌套的时间变化曲线</span><br><span class="line">UIViewAnimationOptionAllowAnimatedContent      //通过改变属性和重绘实现动画效果，如果key没有提交动画将使用快照</span><br><span class="line">UIViewAnimationOptionShowHideTransitionViews   //用显隐的方式替代添加移除图层的动画效果</span><br><span class="line">UIViewAnimationOptionOverrideInheritedOptions  //忽略嵌套继承的选项</span><br></pre></td></tr></table></figure>
<p><strong>时间函数曲线相关</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">UIViewAnimationOptionCurveEaseInOut</span>            <span class="comment">//时间曲线函数，由慢到快</span></span><br><span class="line"><span class="type">UIViewAnimationOptionCurveEaseIn</span>               <span class="comment">//时间曲线函数，由慢到特别快</span></span><br><span class="line"><span class="type">UIViewAnimationOptionCurveEaseOut</span>              <span class="comment">//时间曲线函数，由快到慢</span></span><br><span class="line"><span class="type">UIViewAnimationOptionCurveLinear</span>               <span class="comment">//时间曲线函数，匀速</span></span><br></pre></td></tr></table></figure>
<p><strong>专场动画相关</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">UIViewAnimationOptionTransitionNone</span>            <span class="comment">//无转场动画</span></span><br><span class="line"><span class="type">UIViewAnimationOptionTransitionFlipFromLeft</span>    <span class="comment">//转场从左翻转</span></span><br><span class="line"><span class="type">UIViewAnimationOptionTransitionFlipFromRight</span>   <span class="comment">//转场从右翻转</span></span><br><span class="line"><span class="type">UIViewAnimationOptionTransitionCurlUp</span>          <span class="comment">//上卷转场</span></span><br><span class="line"><span class="type">UIViewAnimationOptionTransitionCurlDown</span>        <span class="comment">//下卷转场</span></span><br><span class="line"><span class="type">UIViewAnimationOptionTransitionCrossDissolve</span>   <span class="comment">//转场交叉消失</span></span><br><span class="line"><span class="type">UIViewAnimationOptionTransitionFlipFromTop</span>     <span class="comment">//转场从上翻转</span></span><br><span class="line"><span class="type">UIViewAnimationOptionTransitionFlipFromBottom</span>  <span class="comment">//转场从下翻转</span></span><br></pre></td></tr></table></figure>
<p><strong>关键帧动画</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">touchesBegan</span><span class="params">(<span class="number">_</span> touches: Set&lt;UITouch&gt;, with event: UIEvent?)</span></span> &#123;</span><br><span class="line">        <span class="comment">//  withRelativeStartTime 相对开始时间</span></span><br><span class="line">        <span class="comment">//  relativeDuration 相对持续时间</span></span><br><span class="line">        <span class="type">UIView</span>.animateKeyframes(withDuration: <span class="number">2</span>, delay: <span class="number">0</span>, options: [], animations: &#123;</span><br><span class="line">            <span class="type">UIView</span>.addKeyframe(withRelativeStartTime: <span class="number">0</span>, relativeDuration: <span class="number">0.4</span>, animations: &#123;</span><br><span class="line">                <span class="keyword">self</span>.lable.transform = <span class="keyword">self</span>.lable.transform.rotated(by: .pi / <span class="number">4</span>)</span><br><span class="line">            &#125;)</span><br><span class="line">            <span class="type">UIView</span>.addKeyframe(withRelativeStartTime: <span class="number">0.4</span>, relativeDuration: <span class="number">0.4</span>, animations: &#123;</span><br><span class="line">                <span class="keyword">self</span>.lable.transform = <span class="keyword">self</span>.lable.transform.scaledBy(x: <span class="number">0.5</span>, y: <span class="number">0.5</span>)</span><br><span class="line">            &#125;)</span><br><span class="line">            <span class="type">UIView</span>.addKeyframe(withRelativeStartTime: <span class="number">0.8</span>, relativeDuration: <span class="number">0.2</span>, animations: &#123;</span><br><span class="line">                <span class="keyword">self</span>.lable.transform = <span class="type">CGAffineTransform</span>(translationX: <span class="number">100</span>, y: <span class="number">0</span>)</span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;) &#123; (finished) <span class="keyword">in</span></span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://ws4.sinaimg.cn/large/006tNc79ly1ft9c7mcwv5g306b07jwey.gif" alt=""></p>
<p><strong>Options</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">UIViewKeyframeAnimationOptionLayoutSubviews        //提交动画的时候布局子控件，表示子控件将和父控件一同动画。</span><br><span class="line">UIViewKeyframeAnimationOptionAllowUserInteraction  //动画时允许用户交流，比如触摸    UIViewKeyframeAnimationOptionBeginFromCurrentState     //从当前状态开始动画</span><br><span class="line">UIViewKeyframeAnimationOptionRepeat                //动画无限重复</span><br><span class="line">UIViewKeyframeAnimationOptionAutoreverse           //执行动画回路,前提是设置动画无限重复</span><br><span class="line">UIViewKeyframeAnimationOptionOverrideInheritedDuration //忽略外层动画嵌套的执行时间</span><br><span class="line">UIViewKeyframeAnimationOptionOverrideInheritedOptions  //忽略嵌套继承的选项</span><br></pre></td></tr></table></figure>
<p><strong>关键帧动画独有的</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">UIViewKeyframeAnimationOptionCalculationModeLinear</span>     <span class="comment">//选择使用一个简单的线性插值计算的时候关键帧之间的值。</span></span><br><span class="line"><span class="type">UIViewKeyframeAnimationOptionCalculationModeDiscrete</span>   <span class="comment">//选择不插入关键帧之间的值,而是直接跳到每个新的关键帧的值。</span></span><br><span class="line"><span class="type">UIViewKeyframeAnimationOptionCalculationModePaced</span>      <span class="comment">//选择计算中间帧数值算法使用一个简单的节奏。这个选项的结果在一个均匀的动画。</span></span><br><span class="line"><span class="type">UIViewKeyframeAnimationOptionCalculationModeCubic</span>      <span class="comment">//选择计算中间帧使用默认卡特莫尔罗花键,通过关键帧的值。你不能调整该算法的参数。 这个动画好像会更圆滑一些..</span></span><br><span class="line"><span class="type">UIViewKeyframeAnimationOptionCalculationModeCubicPaced</span> <span class="comment">//选择计算中间帧使用立方计划而忽略的时间属性动画。相反,时间参数计算隐式地给动画一个恒定的速度。</span></span><br></pre></td></tr></table></figure>
<p><strong>系统删除动画</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">touchesBegan</span><span class="params">(<span class="number">_</span> touches: Set&lt;UITouch&gt;, with event: UIEvent?)</span></span> &#123;</span><br><span class="line">        <span class="type">UIView</span>.perform(<span class="type">UISystemAnimation</span>.delete, on: [lable], options: [], animations: &#123;</span><br><span class="line"></span><br><span class="line">        &#125;) &#123; (finished) <span class="keyword">in</span></span><br><span class="line">            <span class="keyword">self</span>.lable.removeFromSuperview()</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://ws2.sinaimg.cn/large/006tNc79ly1ft9eowfavdg305b074t8q.gif" alt=""></p>
<p><strong>阻塞动画</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">UIView</span>.performWithoutAnimation &#123;</span><br><span class="line">    view.frame = <span class="type">CGRectMake</span>(...)  </span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/07/12/Animation/" rel="next" title="Animation">
                <i class="fa fa-chevron-left"></i> Animation
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/07/20/正则表达式/" rel="prev" title="正则表达式">
                正则表达式 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/10.png"
                alt="Erhqe" />
            
              <p class="site-author-name" itemprop="name">Erhqe</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">70</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">31</span>
                  <span class="site-state-item-name">categories</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">tags</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#UIViewAnimation"><span class="nav-number">1.</span> <span class="nav-text">UIViewAnimation</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#CGAffineTransform"><span class="nav-number">1.1.</span> <span class="nav-text">CGAffineTransform</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#UIViewAnimation-1"><span class="nav-number">2.</span> <span class="nav-text">UIViewAnimation</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Erhqe</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'TiAY2J24ECwQH9uLYsoJpgIK-gzGzoHsz',
        appKey: 'Y9PiVrPXVmfNsv4Aa6cPsADG',
        placeholder: 'Just go go',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
